package com.subsequent.service.impl;

import com.subsequent.entity.Medicines;
import com.subsequent.mapper.MedicinesMapper;
import com.subsequent.service.MedicinesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MedicinesServiceImpl implements MedicinesService {

    @Autowired
    private MedicinesMapper medicinesMapper;

    @Override
    public List<Medicines> selectByCondition(String medicineName, Integer isPrescription, String code, Integer status, String startTime, String endTime) {
        return medicinesMapper.selectByCondition(medicineName, isPrescription, code, status, startTime, endTime);
    }

    @Override
    public int countByCondition(String medicineName, Integer isPrescription, String code, Integer status, String startTime, String endTime) {
        return medicinesMapper.countByCondition(medicineName, isPrescription, code, status, startTime, endTime);
    }

    @Override
    public Medicines selectById(Integer medicineId) {
        return medicinesMapper.selectById(medicineId);
    }

    @Override
    public int insert(Medicines medicines) {
        Date now = new Date();
        medicines.setCreatedAt(now);
        medicines.setUpdatedAt(now);
        return medicinesMapper.insert(medicines);
    }

    @Override
    public int update(Medicines medicines) {
        medicines.setUpdatedAt(new Date());
        return medicinesMapper.update(medicines);
    }

    @Override
    public int deleteById(Integer medicineId) {
        return medicinesMapper.deleteById(medicineId);
    }


}